﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AutoUpdateTool
{
    public partial class MsgView : Form
    {
        private static MsgView _main;
        public MsgView()
        {
            InitializeComponent();
            _main = this;
        }

        public static MsgView CurrentInstance()
        {
            if (_main == null || _main.IsDisposed)
            {
                _main = null;
                _main = new MsgView();
            }
            _main.StartPosition = FormStartPosition.CenterScreen;
            _main.BringToFront();
            _main.Show();
            return _main;
        }

        public static MsgView AppendText(string msg)
        {
            CurrentInstance();
            if (_main.IsHandleCreated && _main.IsDisposed == false)
            {
                _main.txt_InfoLog.BeginInvoke(new ThreadStart(() =>
                    {
                        _main.txt_InfoLog.AppendText(msg);
                    }));
            }
            return _main;
        }
        public static MsgView ShowText(string msg)
        {
            CurrentInstance();
            if (_main.IsHandleCreated && _main.IsDisposed == false)
            {
                _main.txt_InfoLog.BeginInvoke(new ThreadStart(() =>
                {
                    _main.txt_InfoLog.BorderStyle = BorderStyle.FixedSingle;
                    _main.txt_InfoLog.ScrollBars = ScrollBars.Vertical;
                    _main.txt_InfoLog.Text = msg;
                }));
            }
            return _main;
        }

        public static MsgView ShowToast(string msg)
        {
            CurrentInstance();
            if (_main.IsHandleCreated && _main.IsDisposed == false)
            {
                _main.txt_InfoLog.BeginInvoke(new ThreadStart(() =>
                {
                    _main.txt_InfoLog.BorderStyle = BorderStyle.None;
                    _main.txt_InfoLog.ScrollBars = ScrollBars.None;
                    _main.txt_InfoLog.Text = msg;
                }));
            }
            return _main;
        }
    }
}
